package ch.elektroplan.cmueller.logikModulGenerator.presentation.subs;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import ch.elektroplan.cmueller.logikModulGenerator.business.elements.Input;
import ch.elektroplan.cmueller.logikModulGenerator.business.elements.MemoryVariable;

public class MakeMemoryPanel extends JPanel {


	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	JLabel lb_input = new JLabel("Memoryvariablen");
	JButton bu_addInput = new JButton("neuer Eingang");
	int inputnumber = 1;
	
	ArrayList<MemoryVariable> memoryVariables;
	
	public MakeMemoryPanel(ArrayList<MemoryVariable> memoryVariables) {
		
		this.memoryVariables = memoryVariables;

		bu_addInput.addActionListener(new AddinputActionlistener());

		setPreferredSize(new Dimension(400, 800));
		add(lb_input, BorderLayout.NORTH);
		add(bu_addInput, BorderLayout.NORTH);

	}


	private class AddinputActionlistener implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent e) {
			
			MemoryVariable me = new MemoryVariable(inputnumber++);
			memoryVariables.add(me);
			MakeMemoryPanel.this.add(new MemoryVariablePanel(me), BorderLayout.CENTER);
			MakeMemoryPanel.this.revalidate();

		}

	}
}
